package com.example.shopping.Order.controller;

import com.example.shopping.JsonResult;


import com.example.shopping.Order.mapper.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
public class Orders {
    @Autowired
    Order Order;

    //查询所有订单
    @RequestMapping("/api/Orders/List")
    public JsonResult getOrderList() {
        List<com.example.shopping.Order.entity.Orders> order = Order.getOrderList();
        return new JsonResult(true, "查询成功", order);
    }

    //修改订单状态
    @RequestMapping("/api/Orders/Upd")
    public JsonResult UpdateOrders(com.example.shopping.Order.entity.Orders orders){
        int num = Order.UpdateOrders(orders);
        return new JsonResult(true ,"修改成功",num);
    }

    //添加订单
    @RequestMapping("/api/Orders/Add")
    public JsonResult OrdersAdd(com.example.shopping.Order.entity.Orders orders){
        SimpleDateFormat ft=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=new Date();
        String time=ft.format(date);
        orders.setUpdated(time);
        int addOrders = Order.OrderAdd(orders);
        return new JsonResult(true , "添加成功" , addOrders);
    }

    //删除订单
    @RequestMapping("/api/Orders/del")
    public JsonResult DeleteOrders(int id){
        int num = Order.DeleteOrders(id);
        return new JsonResult(true , "删除成功" , num);
    }
}
